export class Debounced {
  /**
   *
   */
  constructor(delay?: number) {
    this.delay = delay ?? 1000;
  }
  delay: number;
  timeout?: number;
  debounced(delay = this.delay) {
    return new Promise((resolve, reject) => {
      if (!this.timeout) {
        this.timeout = setTimeout(() => {
          resolve('success');
        }, 0);
      } else {
        clearTimeout(this.timeout);
        this.timeout = setTimeout(() => {
          resolve('success');
          this.timeout = undefined;
        }, delay);
      }
    });
  }
}
